home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / quicktime for java / zoo tutorial / module10- qtzoo / completed source / mappane.java < prev    next >
Encoding:
Java Source  |  2000-09-28  |  10.8 KB  |  293 lines

  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.io.*;
  4. import java.util.Hashtable;
  5.  
  6. import quicktime.*;
  7. import quicktime.qd.*;
  8. import quicktime.std.*;
  9. import quicktime.io.*;
  10. import quicktime.sound.*;
  11. import quicktime.std.image.*;
  12. import quicktime.std.music.*;
  13. import quicktime.std.movies.*;
  14. import quicktime.util.*;
  15. import quicktime.app.display.*;
  16. import quicktime.app.image.*;
  17. import quicktime.app.anim.*;
  18. import quicktime.app.actions.*;
  19.  
  20. import quicktime.app.audio.*;
  21.  
  22. import quicktime.app.event.QTActionEvent;  
  23. import quicktime.app.event.QTActionListener;
  24. import quicktime.app.event.QTMouseTargetController; 
  25.  
  26. import quicktime.app.QTFactory;
  27. import quicktime.std.movies.media.DataRef;
  28. import quicktime.app.players.QTPlayer;
  29.  
  30. /**
  31.  * QTZoo Module 10 - Putting it all together
  32.  * This sample requires QuickTime for Java 4.1
  33.  *
  34.  * The Map pane that contains the main map interface
  35.  *
  36.  * @author Levi Brown
  37.  * @author Michael Hopkins
  38.  * @author Apple Computer, Inc.
  39.  * @version 10.0 10/21/1999
  40.  * 
  41.  * Copyright:     © Copyright 1999 Apple Computer, Inc. All rights reserved.
  42.  *    
  43.  * Disclaimer:    IMPORTANT:  This Apple software is supplied to you by Apple Computer, Inc.
  44.  *                ("Apple") in consideration of your agreement to the following terms, and your
  45.  *                use, installation, modification or redistribution of this Apple software
  46.  *                constitutes acceptance of these terms.  If you do not agree with these terms,
  47.  *                please do not use, install, modify or redistribute this Apple software.
  48.  *
  49.  *                In consideration of your agreement to abide by the following terms, and subject
  50.  *                to these terms, Apple grants you a personal, non-exclusive license, under Apple’s
  51.  *                copyrights in this original Apple software (the "Apple Software"), to use,
  52.  *                reproduce, modify and redistribute the Apple Software, with or without
  53.  *                modifications, in source and/or binary forms; provided that if you redistribute
  54.  *                the Apple Software in its entirety and without modifications, you must retain
  55.  *                this notice and the following text and disclaimers in all such redistributions of
  56.  *                the Apple Software.  Neither the name, trademarks, service marks or logos of
  57.  *                Apple Computer, Inc. may be used to endorse or promote products derived from the
  58.  *                Apple Software without specific prior written permission from Apple.  Except as
  59.  *                expressly stated in this notice, no other rights or licenses, express or implied,
  60.  *                are granted by Apple herein, including but not limited to any patent rights that
  61.  *                may be infringed by your derivative works or by other works in which the Apple
  62.  *                Software may be incorporated.
  63.  *
  64.  *                The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO
  65.  *                WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
  66.  *                WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  67.  *                PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
  68.  *                COMBINATION WITH YOUR PRODUCTS.
  69.  *
  70.  *                IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
  71.  *                CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  72.  *                GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  73.  *                ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
  74.  *                OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
  75.  *                (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
  76.  *                ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  77.  * 
  78.  */
  79. public class MapPane extends ZooPane
  80. {
  81.     public MapPane( Progress progress ) 
  82.     {
  83.         try
  84.         {    
  85.             QDRect size = new QDRect(MainFrame.WIDTH, MainFrame.HEIGHT);
  86.             QDGraphics gw = new QDGraphics (size);
  87.             compositor = new Compositor (gw, QDColor.white, 20, 1);
  88.             
  89.             progress.updateProgress("Looking for the North Star...");
  90.  
  91.             QTFile waterPict = new QTFile (QTFactory.findAbsolutePath ("data/map/water.pict"));
  92.             GraphicsImporterDrawer waterDrawer = new GraphicsImporterDrawer(waterPict);
  93.             waterDrawer.setDisplayBounds (size);
  94.             ImagePresenter water = ImagePresenter.fromGraphicsImporterDrawer(waterDrawer);
  95.             compositor.addMember(water, 6);
  96.  
  97.             progress.updateProgress();    
  98.                         
  99.             QTFile                 islandFile = new QTFile( QTFactory.findAbsolutePath( "data/map/island.pict" ));
  100.             ImagePresenter         islandPresenter = ImagePresenter.fromFile( islandFile );
  101.             ImageDataSequence     islandDS = new ImageDataSequence (islandPresenter.getDescription());
  102.             
  103.             islandDS.addMember( islandPresenter.getImage() );
  104.  
  105.             progress.updateProgress();    
  106.             
  107.             if ((QTSession.isCurrentOS(QTSession.kWin32) && QTSession.getQTMajorVersion() == 3) == false)    //doesn't work on QT3.0.2 on Win
  108.                 islandDS = ImageUtil.makeTransparent ( islandDS, QDColor.white );
  109.             
  110.             Matrix theMatrix = new Matrix();
  111.             theMatrix.translate( (float) 10, (float) 5 );
  112.             TwoDSprite island = new TwoDSprite( islandDS, theMatrix, true, 2 );
  113.             
  114.             progress.updateProgress();    
  115.             compositor.addMember(island, 4);            
  116.             
  117.             ctr = new QTMouseTargetController( false );
  118.             ctr.addQTMouseListener( new PaneMouseListener( QDColor.black, QDColor.darkGray, QDColor.lightGray ));
  119.             progress.updateProgress();    
  120.             
  121.             compositor.addController (ctr);
  122.                         
  123.             TwoDSprite currentSprite;
  124.             areas = new Hashtable(6);
  125.  
  126.             progress.updateProgress("Consulting the cartographer...");
  127.             currentSprite = CreateRegion( compositor, "data/map/area1.pict",  3, 60, 19 );
  128.             areas.put(currentSprite, "zebra");
  129.  
  130.             progress.updateProgress();
  131.             currentSprite = CreateRegion( compositor, "data/map/area2.pict",  3, 229, 38 );
  132.             areas.put(currentSprite, "giraffe");
  133.             progress.updateProgress();
  134.             currentSprite = CreateRegion( compositor, "data/map/area3.pict",  3, 396, 92 );
  135.             areas.put(currentSprite, "tiger");
  136.             progress.updateProgress();
  137.             currentSprite = CreateRegion( compositor, "data/map/area4.pict",  3, 45, 192 );
  138.             areas.put(currentSprite, "rhino");
  139.             progress.updateProgress();
  140.             currentSprite = CreateRegion( compositor, "data/map/area5.pict",  3, 147, 208 );
  141.             areas.put(currentSprite, "bear");
  142.             progress.updateProgress();
  143.             currentSprite = CreateRegion( compositor, "data/map/area6.pict",  3, 261, 245 );
  144.             areas.put(currentSprite, "elephant");
  145.             progress.updateProgress();
  146.             
  147.             exitCtr = new QTMouseTargetController( false );
  148.             exitCtr.addQTMouseListener( new PaneMouseListener( QDColor.darkGray, QDColor.white, QDColor.lightGray));
  149.  
  150.             currentSprite = CreateExit( compositor, "data/map/SailAway.pict", 3, 20, 400 );
  151.             areas.put(currentSprite, "exit");
  152.             compositor.addController( exitCtr );
  153.  
  154.             progress.updateProgress();
  155.             CreateRollover( compositor, "data/map/zebra.pict",    2, 109, 95 );
  156.  
  157.             progress.updateProgress();
  158.             CreateRollover( compositor, "data/map/giraffe.pict",  2, 281, 65 );
  159.             progress.updateProgress();
  160.             CreateRollover( compositor, "data/map/tiger.pict",    2, 445, 176 );
  161.             progress.updateProgress();
  162.             CreateRollover( compositor, "data/map/rhino.pict",    2, 133, 252 );
  163.             progress.updateProgress();
  164.             CreateRollover( compositor, "data/map/bear.pict",     2, 220, 299 );
  165.             progress.updateProgress();
  166.             CreateRollover( compositor, "data/map/elephant.pict", 2, 343, 286 );
  167.         }
  168.         catch (Exception e)
  169.         {
  170.             e.printStackTrace();
  171.         }
  172.     }
  173.  
  174.     /**
  175.      * Called to do any setup after being set as the client of the QTCanvas.
  176.      * May be used to start effects running, movies playing, etc.
  177.      */
  178.     public void start()
  179.     {
  180.     }
  181.  
  182.     /**
  183.      * Called to do clean up after being removed as the client of the QTCanvas.
  184.      * Should be used to stop effects running, movies playing, etc.
  185.      */
  186.     public void stop()
  187.     {
  188.     }
  189.     
  190.     /**
  191.      * Utility routines for creating the various animal regions
  192.      * Creates region from relative file path and creates a TwoDSprite
  193.      */
  194.     protected TwoDSprite CreateRegion( Compositor comp, String filename, int layer, int x, int y )
  195.     {
  196.         TwoDSprite sprite = null;
  197.         
  198.         try
  199.         {
  200.             QTFile                 file = new QTFile( QTFactory.findAbsolutePath( filename ));
  201.             ImagePresenter         presenter = ImagePresenter.fromFile( file );
  202.             ImageDataSequence     dataSeq = new ImageDataSequence (presenter.getDescription());
  203.             
  204.             dataSeq.addMember( presenter.getImage() );
  205.             
  206.             if ((QTSession.isCurrentOS(QTSession.kWin32) && QTSession.getQTMajorVersion() == 3) == false)    //doesn't work on QT3.0.2 on Win
  207.                 dataSeq = ImageUtil.makeTransparent ( dataSeq, QDColor.white );
  208.             
  209.             Matrix theMatrix = new Matrix();
  210.             theMatrix.translate( (float) x, (float) y );
  211.             sprite = new TwoDSprite( dataSeq, theMatrix, true, 10 );
  212.             
  213.             GraphicsMode normalGM = new GraphicsMode (QDConstants.blend, QDColor.black);
  214.             sprite.setGraphicsMode (normalGM);
  215.             comp.addMember(sprite, layer);
  216.             ctr.addMember( sprite );
  217.         }
  218.         catch ( Exception e )
  219.         {
  220.             e.printStackTrace();
  221.         }
  222.  
  223.         return sprite;
  224.     }
  225.     
  226.     /**
  227.      * Utility routines for creating the "Sail Away" sprite on the map pane
  228.      * Creates region from relative file path and creates a twoDSprite
  229.      */
  230.     protected TwoDSprite CreateExit( Compositor comp, String filename, int layer, int x, int y )
  231.     {
  232.         TwoDSprite sprite = null;
  233.         
  234.         try
  235.         {
  236.             QTFile                 file = new QTFile( QTFactory.findAbsolutePath( filename ));
  237.             ImagePresenter         presenter = ImagePresenter.fromFile( file );
  238.             ImageDataSequence     dataSeq = new ImageDataSequence (presenter.getDescription());
  239.             
  240.             dataSeq.addMember( presenter.getImage() );
  241.             
  242.             if ((QTSession.isCurrentOS(QTSession.kWin32) && QTSession.getQTMajorVersion() == 3) == false)    //doesn't work on QT3.0.2 on Win
  243.                 dataSeq = ImageUtil.makeTransparent ( dataSeq, QDColor.blue );
  244.             
  245.             Matrix theMatrix = new Matrix();
  246.             theMatrix.translate( (float) x, (float) y );
  247.             sprite = new TwoDSprite( dataSeq, theMatrix, true, 10 );
  248.             
  249.             GraphicsMode normalGM = new GraphicsMode (QDConstants.blend, QDColor.darkGray);
  250.             sprite.setGraphicsMode (normalGM);
  251.             comp.addMember(sprite, layer);
  252.             exitCtr.addMember( sprite );
  253.         }
  254.         catch ( Exception e )
  255.         {
  256.             e.printStackTrace();
  257.         }
  258.  
  259.         return sprite;
  260.     }
  261.     
  262.     /**
  263.      * Utility routines for creating the various animal icons
  264.      * Creates region from relative file path and creates a twoDSprite
  265.      */
  266.     public void CreateRollover( Compositor comp, String filename, int layer, int x, int y )
  267.     {
  268.         try
  269.         {
  270.             QTFile                 file = new QTFile( QTFactory.findAbsolutePath( filename ));
  271.             ImagePresenter         presenter = ImagePresenter.fromFile( file );
  272.             ImageDataSequence     dataSeq = new ImageDataSequence (presenter.getDescription());
  273.             
  274.             dataSeq.addMember( presenter.getImage() );
  275.             
  276.             if ((QTSession.isCurrentOS(QTSession.kWin32) && QTSession.getQTMajorVersion() == 3) == false)    //doesn't work on QT3.0.2 on Win
  277.                 dataSeq = ImageUtil.makeTransparent ( dataSeq, QDColor.blue );
  278.             
  279.             Matrix theMatrix = new Matrix();
  280.             theMatrix.translate( (float) x, (float) y );
  281.             TwoDSprite sprite = new TwoDSprite( dataSeq, theMatrix, true, 10 );
  282.             
  283.             comp.addMember(sprite, layer);
  284.         }
  285.         catch ( Exception e )
  286.         {
  287.             e.printStackTrace();
  288.         }
  289.     }
  290.  
  291.     protected QTMouseTargetController exitCtr;
  292. }
  293.